public class DummyMove {

	public static byte maze[][] = new byte[9][9];
	public static String charmaze[] = new String[9];
	public static int position[] = new int[2];
	public static int goal[] = new int[2];
	public static int direction;
	
	// Goal is redundant
	public static final byte GOALX = 3, GOALY = 3, STARTX = 0, STARTY = 1;
	public static final int GOLEFT = 0, GORIGHT = 1;
    public static final int FORWARD = 1, BACKWARD = 0;
	public static final int SOUTH = 0, EAST = 1, NORTH = 2, WEST = 3;
	public static final byte UNVISITED = 0, VISITED = 1, NOWALL = 2, WALL = 3;

	public static int head[][]=new int[100][3];
    public static int pointer = -1;
	/* CM : i try to clean up this code and see if mymaze works
    public boolean isPathEmpty(){
        return pointer == -1;
    }
    
    public void push(int x,int y,int direction){
        if(pointer+1 < head.length)
        {
        	pointer++;
        	head[pointer][0] = x;
        	head[pointer][1] = y;
        	head[pointer][2] = direction;
        	
        }
    }
    
    public int[] pop(){
        if(isPathEmpty())
            return new int[3];
        	
        return head[pointer--];
    }
    */
	public DummyMove()
	{
		// rows are being set so it's X THEN Y
		charmaze[0] =   "*********";
		charmaze[1] =	"*       *";
		charmaze[2] =	"*** *** *";
		charmaze[3] =	"* * *   *";
		charmaze[4] =	"*** *****";
		charmaze[5] =	"*       *";
		charmaze[6] =	"***** * *";
		charmaze[7] =	"*     * *";
		charmaze[8] =	"*********";

		for (int i = 0; i < 9; i++)
			for (int j = 0; j < 9; j++)
			{
				if (charmaze[i].charAt(j) == '*')
					maze[i][j] = WALL;
				else 
					maze[i][j] = UNVISITED;
			}

		direction = DummyMove.SOUTH;
	
		// x axis map to j (columns)
		// y axis map to i (rows)
		// odd indexes are paths : impt to keep that in mind
		// easier to imagine 0,0 at top left corner ; we should keep that in mind too
		goal[0] = (2*GOALX)+1;  // goal is at (3,3) 
		goal[1] = (2*GOALY)+1;
		position[0] = (2*STARTX)+1; // start is at (0,0)
		position[1] = (2*STARTY)+1;
	}

	public void initialize(int startX,int startY,int goalX,int goalY)
	{
			this.position[0]=(2*startX)+1;
			this.position[1]=(2*startY)+1;
			this.goal[0]=(2*goalX)+1;
			this.goal[1]=(2*goalX)+1;
	}
	
	public static boolean forward(int dist)
	{
		for (int i = 0; i < dist; i++)
		{
			if (direction == DummyMove.NORTH)
			{
				if (maze[position[1]-1][position[0]]==WALL)
					return false;
				position[1] -= 2;
				return true;
			}
			else if (direction == DummyMove.SOUTH)
			{
				if (maze[position[1]+1][position[0]]==WALL)
					return false;
				position[1] += 2;
				return true;
			}
			else if (direction == DummyMove.EAST)
			{
				if (maze[position[1]][position[0]+1]==WALL)
					return false;
				position[0] += 2;
				return true;
			}
			else//if (direction == DummyMove.WEST)
			{
				if (maze[position[1]][position[0]-1]==WALL)
					return false;
				position[0] -= 2;
				return true;
			}
		}
		return true;
	}

	public static boolean backward(int dist){return true;}

	public static boolean right(){
		if (direction == SOUTH)
			direction = WEST;
		else
			direction--;
		return true;
	}

	public static boolean left(){
		if (direction == WEST)
			direction = SOUTH;
		else
			direction++;
		return true;
	}

	public static void print(int x,int y)
	{
		String s = Integer.toString(x)+" "+Integer.toString(y);
		lcd(s);
	}
	
	public static void lcd(String s) {
		System.out.println(s);
		printMaze();
	}
	
	public static void printMaze()
	{
		for (int i = 0; i < 9; i++)
		{
			for (int j = 0; j < 9; j++)
			{
				if(i == position[1] && j == position[0])
					System.out.print('$');
				else
					System.out.print(charmaze[i].charAt(j));
			}
			System.out.println();
		}
	}

	public static void beep() {
		System.out.println("BEEEEEP!");
	}

	// removed rest and this is purely a testing class
}
